<?php
/**
* @software         [JiJinCMS]
* @author           [上海集锦信息科技有限公司]
* @website          [http://www.jijinweb.com]
* @email            [sunny@jijinweb.com]
**/
namespace app\admin\validate;
use think\validate;
use think\facade\Db;
use think\facade\Request;
class ModelValidate extends validate{
    public $rule = [
        'name'  => ['require','unique'=>'model'],
        'table_id'  => ['require','checkTable'],
    ];
    protected $message = [
        'name.require'=>'请填写模型名称',
        'name.unique'=>'模型名已存在',
        'table_id.require'=>'缺少table_id！',
        'table_id.checkTable'=>'数据表不存在',
    ];
    //验证数据表是否已存在
    protected function checkTable($value, $rule){
        $table_name=Db::name("table")->where('table_id',$value)->value("table_name");
        return !!table_exists("cms_".$table_name);
    }
}

